/*
 *  cmd_handler.h
 *  peertopeer
 *
 *  Created by jihed kamkoum on 09/05/10.
 *  Copyright 2010 ENSEIRB. All rights reserved.
 *
 */
#ifndef CMD_HANDLER_H_
#define CMD_HANDLER_H_

#include "../common/common.h"
#include "../listes/clientlist.h"
#include "../listes/filelist.h"
#include "../listes/listeUpload.h"
#include "../listes/listeDownload.h"
#include "../file/file.h"
#include "../protocole/protocole.h"
#include "../common/scheduler.h"
typedef struct _md5computer{
	int semid;
	filelist_t * listeFichiers;
	pthread_mutex_t * fileTableAccess;
	char * path;
	char  ip[TAILLE_IP];
	int port;
}md5computer;

typedef struct _cmdrecv{
	int sock;//socket de la partie serveur
	int csock;//socket de la partie client
	pthread_mutex_t * clientSocketAccess;
	int semid;
	char * ip_s;
	int port_s;
	char * path;
	const char * cmd;
	clientlist_t * listeClients;
	pthread_mutex_t * clientTableAccess;
	filelist_t * listeFichiers;
	pthread_mutex_t * fileTableAccess;
	ListeUpload * listeUpload;
	pthread_mutex_t * uploadTableAccess;
	ListeDownload * listeDownload;
	pthread_mutex_t * downloadTableAccess;
	int pipe1;
	pthread_mutex_t * neighbourhoodCondMutex;
	pthread_cond_t * neighbourhoodCond;
	int  * neighbourhoodbool;
	pthread_mutex_t * listCondMutex;
	pthread_cond_t * listCond;
	int  * listbool;
	pthread_mutex_t * trafficCondMutex;
	pthread_cond_t * trafficCond;
	int  * trafficbool;
}cmdrecv;
void cmd_neighbourhoud_handler(cmdrecv* recived);
void cmd_get_handler(cmdrecv * recived);
void cmd_checksum_handler(cmdrecv * recived);
void cmd_list_handler(cmdrecv* recived);
void cmd_raw_handler(cmdrecv * recived);
void cmd_traffic_handler(cmdrecv * recived);
void * f_thread_md5computer(md5computer * compute);
void timeout_handler(int *connectlist,clientlist_t * listeClients, float time_out);
void calculemd5(int semid,char * path,filelist_t * listeFichiers,pthread_mutex_t * fileTableAccess,char * ip,int port);
int getRoundPort(char * ip);
/*
 *Ouverture de la socket serveur en mode TCP
 */
void create_serveur_sock(SOCKET * sock);
void sock_puts(int sock,const char* message);

#endif
